package com.gh.strategy.impl;

import com.gh.anno.Strategy;
import com.gh.strategy.GetSumStrategy;
import org.springframework.stereotype.Component;

import java.math.BigDecimal;
import java.util.List;

/**
 * @author heyu
 * @date 2022:11:06 10:00
 * FullReduction  总价打折
 */
@Strategy("FullReduction")
@Component
public class SumStrategyFullReduction implements GetSumStrategy {
    @Override
    public BigDecimal getSum(List<BigDecimal> prices) {
        BigDecimal sum = BigDecimal.valueOf(0);
        for (BigDecimal price : prices) {
            sum = sum.add(price);
        }

        //四舍五入
        double divisor = Double.valueOf(String.valueOf(sum));
        double a = Math.floor(divisor);

        return sum.subtract(BigDecimal.valueOf(a / 10));

    }
}
